<?php
	//echo "ssss";
	function count_page($gioi_han)
	{
		
		
			$tv="select count(*) from san_pham where thuoc_menu='$_GET[id]'";
			$tv_1=mysql_query($tv);
			$tv_2=mysql_fetch_array($tv_1);
			$so=$tv_2[0];
			$kq=ceil($so/$gioi_han);
		
		return $kq;
	}
	
	
	
	
?>
<?php
	$n_col=3;
	$sd=5;
	$gioi_han=$n_col*$sd;
	if($_GET['trang']=="")
	{
		$vtbd=0;
	}
	else 
	{
		$vtbd=($_GET['trang']-1)*$gioi_han;
	}
	$num_page=count_page($gioi_han);
	//echo $vtbd;
	echo "<hr>";
	echo "<table border='1'>";
		//$tv="select * from san_pham ";
		$tv="select * from san_pham where thuoc_menu='$_GET[id]' order by id desc limit $vtbd,$gioi_han";
		$tv_1=mysql_query($tv);
		while($tv_2=mysql_fetch_array($tv_1))
		{
			for($i=1;$i<=$n_col;$i++)
			{
			if($i!=1){ $tv_2=mysql_fetch_array($tv_1) ;}
			if($i==1) echo "<tr>";
					echo "<td width= '216px' align='center'>";
						$link_hinh="image_flash/san_pham/".$tv_2['hinh'];
						$link_detail="?thamso=chi_tiet_san_pham&id=$tv_2[id]";
						echo "<a href='$link_detail'>";	
							echo "<img border='0' src='$link_hinh' width='150px' height='170px'  >";
						echo "</a>";
						echo "<br>";
						echo "<a href='$link_detail'>";
							echo $tv_2['ten'];
						echo "</a>";
						echo "<br>";
						echo $tv_2['gia'];
					echo "</td>";	
			if($i==$n_col) echo "</tr>";
			}
		}
			echo "<tr>";
				echo "<td colspan='10' align ='center'>";
				
				for($i=1;$i<=$num_page;$i++)
				{
					$link="?thamso=xuat&id=$_GET[id]&trang=$i";
					echo "<a href='$link'>";
						echo $i;
					echo "</a>"; echo " ";
				}	
				echo "</td";
			echo "</tr>";
	
	echo"</table>"

?>